/**
 * 请求拦截器，用于在请求头中添加token
 */
import { getCookie, deleteCookie } from './cookieUtils';

/**
 * 从cookie获取token
 * @returns token字符串或null
 */
export const getToken = (): string | null => {
  return getCookie('token');
};

/**
 * 设置请求头的授权信息
 * @param headers 请求头对象
 */
export const setAuthHeader = (headers: Record<string, string>): void => {
  const token = getToken();
  if (token) {
    headers['Authorization'] = `Bearer ${token}`;
  }
};

/**
 * 清除token，用于登出
 */
export const clearToken = (): void => {
  deleteCookie('token');
};